
<?php

require 'config_inc.php';
require 'dal_common.php';
require 'dal_session.php';
require 'dal_mocool.php';
require 'dal_friend.php';
require 'dal_avatar.php';
require 'api_common.php';

$t_args = get_params(Array(
	'token' => '+token',
	'friend' => '+number',
	'source' => '+any'
));
if ($t_args == null) {
	echo 'ERROR=INVALID_PARAMETER;';
	return;
}

$t_userid = dal_session_get($t_args['token']);
if ($t_userid <= 0) {
	echo 'ERROR=INVALID_TOKEN';
	return;
}

if (!dal_avatar_exist($t_args['friend'])) {
	echo 'ERROR=NOT_EXISTED';
	return;
}

if (!dal_friend_insert($t_userid, $t_args['friend'], $t_args['source'])) {
	echo 'ERROR=SYSTEM_ERROR';
	return;
}

echo 'ERROR=0';
?>
